package com.quwan.common;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.quwan.app.vo.PushOfflineMsgParams;
import com.quwan.constans.AppConst;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author quan
 * @date 2021-06-08 9:53
 */

public abstract class BaseService {
    protected Logger logger = LoggerFactory.getLogger(getClass());


    protected PushOfflineMsgParams pushOffLineMsg(Long mId, String type, String orderId, String title, String content, Byte msgType) {
        Map<String, String> map = new HashMap<>(2);
        if (StringUtils.isNotBlank(type))
            map.put("type", type);
        map.put("orderId", orderId);
        return new PushOfflineMsgParams()
                .setMId(mId)
                .setType(AppConst.OFFLINE_MSG_ORDER_ORDER_HANDLE)
                .setTitle(title)
                .setContent(content)
                .setMap(map);


    }

    /**
     * @param separator 切割符
     * @param str       要转化的字符串
     * @return
     */
    protected List<String> strToList(final String separator, final String str) {
        if (StringUtils.isBlank(separator) || "null".equals(separator) || StringUtils.isBlank(str) || "null".equals(str))
            return Lists.newArrayList();
        else
            return Splitter.on(separator).trimResults().splitToList(str);
    }

    /**
     * @param parts
     * @return
     */
    protected String listToStr(final Iterable<?> parts) {
        if (parts == null)
            return "";
        else
            return Joiner.on(",").join(parts);
    }

    protected String parseArea(String area) {
        if (StringUtils.isBlank(area) || "null".equals(area))
            return "";
        int index = area.lastIndexOf(" ") == -1 ? 0 : area.lastIndexOf(" ") + 1;
        return area.substring(index);
    }


}
